package com.pignest.hotel.dao.hibernate;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.pignest.framework.dao.BaseHibernateDao;
import com.pignest.hotel.beans.TbAccounts;
import com.pignest.hotel.beans.TbLiveInfo;
import com.pignest.hotel.beans.TbLiveRoomMx;
import com.pignest.hotel.util.PageResult;
import com.pignest.hotel.util.WhereCreator;

public class InComeItemDao extends BaseHibernateDao implements
		com.pignest.hotel.dao.InComeItemDao {

	@SuppressWarnings("unchecked")
	@Override
	public PageResult query(PageResult page, String... mxid) {
		String hql = " select b,x  from   TbLiveInfo b ,TbLiveRoomMx x  where b.tbLiveRoomMx.mxid= x.mxid  ";
		String countHql = " select count(*) from  TbLiveInfo b ,TbLiveRoomMx x where b.tbLiveRoomMx.mxid= x.mxid   ";
		WhereCreator where = new WhereCreator(false);
		where.formatAdd(" x.mxid in(%s) ", where.getInstr(mxid));
        String orderby=" order by b.endtime desc ";
		List listcount = getHibernateTemplate().find(countHql + where ,
				where.getParame());
		Long rn = (Long) listcount.get(0);
		page.setRowCount(rn.intValue());
		if (rn == 0)
			return new PageResult();
		List list = this.findByHQL(hql + where+ orderby, where.getParame(), page, false);
		List resultList = new ArrayList<TbLiveInfo>();
		for (Object obj : list) {
			Object[] mx = (Object[]) obj;
			resultList.add((TbLiveInfo) mx[0]); 
		}
		page.setData(resultList);
		return page;
	}

	@Override
	public void addItem(TbAccounts bAccount) {
		this.getHibernateTemplate().save(bAccount);
        
	}
	


	@Override
	public TbLiveRoomMx findById(String mx) {
		return   (TbLiveRoomMx) this.getHibernateTemplate().get(TbLiveRoomMx.class, mx);
	}

	@Override
	public void modify(TbLiveInfo info) { 
		this.getHibernateTemplate().update(info);
	}

	@Override
	public void save(TbLiveInfo info) {
		this.getHibernateTemplate().save(info);
	}

}
